package com.wofish.web.controller.pay;

import com.wofish.common.annotation.Log;
import com.wofish.common.core.controller.BaseController;
import com.wofish.common.core.domain.AjaxResult;
import com.wofish.common.core.page.TableDataInfo;
import com.wofish.common.enums.BusinessType;
import com.wofish.common.utils.poi.ExcelUtil;
import com.wofish.pay.domain.PayCategory;
import com.wofish.pay.service.IPayCategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 支付方式分类 信息操作处理
 * 
 * @author wofish
 * @date 2019-06-11
 */

@Controller
@RequestMapping("/goods/payCategory")
public class PayCategoryController extends BaseController {
    private String prefix = "goods/payCategory";
	
	@Autowired
	private IPayCategoryService payCategoryService;
	
	@RequiresPermissions("goods:payCategory:view")
	@GetMapping()
	public String payCategory() {
	    return prefix + "/payCategory";
	}
	
	/**
	 * 查询支付方式分类列表
	 */

	@RequiresPermissions("goods:payCategory:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(PayCategory payCategory) {
		startPage();
        List<PayCategory> list = payCategoryService.selectPayCategoryList(payCategory);
		return getDataTable(list);
	}
	



	/**
	 * 导出支付方式分类列表
	 */
	@RequiresPermissions("goods:payCategory:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PayCategory payCategory) {
		List<PayCategory> list = payCategoryService.selectPayCategoryList(payCategory);
        ExcelUtil<PayCategory> util = new ExcelUtil<PayCategory>(PayCategory.class);
        return util.exportExcel(list, "payCategory");
    }
	
	/**
	 * 新增支付方式分类
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存支付方式分类
	 */
	@RequiresPermissions("goods:payCategory:add")
	@Log(title = "支付方式分类", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(PayCategory payCategory) {
		return toAjax(payCategoryService.insertPayCategory(payCategory));
	}

	/**
	 * 修改支付方式分类
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
		PayCategory payCategory = payCategoryService.selectPayCategoryById(id);
		mmap.put("payCategory", payCategory);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存支付方式分类
	 */

	@RequiresPermissions("goods:payCategory:edit")
	@Log(title = "支付方式分类", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(PayCategory payCategory) {
		return toAjax(payCategoryService.updatePayCategory(payCategory));
	}
	
	/**
	 * 删除支付方式分类
	 */

	@RequiresPermissions("goods:payCategory:remove")
	@Log(title = "支付方式分类", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(payCategoryService.deletePayCategoryByIds(ids));
	}
	
}
